package com.yunxi.controller.sat;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sat.pojo.MsgTemplateVO;
import com.yunxi.sat.service.MsgTemplateDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 消息模板 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-08-21
 */
@RestController
@RequestMapping("/admin/msgtemplate")
@Api(tags = "pms:msgtemplate", description = "消息模板接口")
public class MsgTemplateController {
    private static final Logger logger = LoggerFactory.getLogger(MsgTemplateController.class);

    @Autowired
    MsgTemplateDubboService msgTemplateDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(MsgTemplateVO msgTemplateVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(msgTemplateDubboService.findPageByVO(msgTemplateVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询列表")
    public ApiResult list(MsgTemplateVO msgTemplateVO) throws Exception {
        return ResponseUtil.ok(msgTemplateDubboService.listByVo(msgTemplateVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(MsgTemplateVO msgTemplateVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(msgTemplateDubboService.getById(msgTemplateVO.getTemplateId()));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody MsgTemplateVO msgTemplateVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        msgTemplateDubboService.saveOrUpdate(msgTemplateVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody List<MsgTemplateVO> msgTemplateVOList) throws Exception {
        msgTemplateDubboService.removeByListVo(msgTemplateVOList);
        return ResponseUtil.ok("success");
    }

}
